package baseFx.tests.springboot;

import baseFx.common.context.spring.BeanScopes;
import baseFx.log.FxLog;
import baseFx.springboot.FxSpringApplication;
import baseFx.springboot.context.WebApplicationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TestApp extends FxSpringApplication implements ApplicationRunner {
    private static Logger logger = LoggerFactory.getLogger(TestApp.class);

    public static void main(String[] args) {
        FxLog.allow.add("baseFx.tests.*");
        TestApp app = new TestApp();
        app.isContextWithRequest = true;
        app.run();
    }

    @Override
    protected void initApplicationContext(WebApplicationContext context) {
        context.addDefaultScope(TestController.class.getCanonicalName(), BeanScopes.SCOPE_CONTEXT);
        context.addDefaultScope(TestApp.class.getPackage().getName() + ".apis*.*", BeanScopes.SCOPE_CONTEXT);
    }

    @Override
    protected Integer getPort() {
        return 8899;
    }

    @Override
    protected void appStartup(WebApplicationContext context, ApplicationArguments args) {
        logger.info("started on {}", getPort());

        getMvcEvents().actionAfter.add((t, s) -> {
            System.out.println(s.handler);
        });
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        logger.info("AppRunner {}", this);
    }
}
